package 结构器模式.享元模式;

import javax.swing.*;
import java.util.HashMap;

/**
 * @Description 工厂类：将该类设计为单例
 * @Author shallow
 * @Date 2023/3/6 14:20
 */

public class BoxFactory {
    //在构造方法中进行初始化操作
    private  HashMap<String,AbstractBox> map;
    //单例模式
    private static BoxFactory factory = new BoxFactory();
    private BoxFactory(){
        map = new HashMap<>();
        map.put("I",new IBox());
        map.put("O",new OBox());
        map.put("L",new LBox());
    }

    //获取该类对象
    public static BoxFactory getInstance(){
        return factory;
    }
    //根据名称获取图形对象
    public AbstractBox getShape(String name){
        return map.get(name);
    }
}
